import axios from 'axios'
// 配置请求的基准URL地址
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
}, err => {
  console.log(err)
})
// 登陆的接口调用
export const loginApi = (data) => {
  return axios.post('login', data)
}
// home 页面左侧导航列表的接口调用
export const asideListApi = (data) => {
  return axios.get('menus', data)
}
// 获取所有用户信息的接口调用
export const getAllApi = (data) => {
  return axios.get('users', { params: data })
}
// 修改用户状态的接口调用
export const userStateApi = (uId, type) => {
  return axios.put(`users/${uId}/state/${type}`)
}
// 添加用户的接口调用
export const addUserApi = (data) => {
  return axios.post('users', data)
}
// 根据id查询用户信息
export const editUserApi = (id) => {
  return axios.get('users/' + id)
}
// 编辑用户提交接口调用
export const editUserInfoApi = (data) => {
  return axios.put('users/' + data.id, { email: data.email, mobile: data.mobile })
}
// 删除用户的接口调用
export const deleteUserApi = (id) => {
  return axios.delete('users/' + id)
}
// power 部分获取全部列表的接口调用
export const getAllRightsApi = () => {
  return axios.get('rights/list')
}
// power 部分获取所有角色列表的接口调用
export const getAllRolesApi = () => {
  return axios.get('roles')
}
// power 部分添加角色的接口调用
export const addRolesApi = (data) => {
  return axios.post('roles', data)
}
// power 根据id查询角色的接口调用
export const queryRolesApi = (id) => {
  return axios.get('roles/' + id)
}
// power 编辑提交角色
export const editRolesApi = (data) => {
  return axios.put('roles/' + data.id, { roleName: data.roleName, roleDesc: data.roleDesc })
}
// power 删除角色的接口调用
export const deleteRolesApi = (id) => {
  return axios.delete('roles/' + id)
}
// power 获取树形结构的所有权限列表
export const getAllTreeRightsApi = () => {
  return axios.get('rights/tree')
}
// power 移除角色权限
export const removeRolesApi = (role, rightId) => {
  return axios.delete(`roles/${role.id}/rights/${rightId}`)
}
// power 角色授权的接口调用
export const setRolesApi = (roleId, rids) => {
  return axios.post(`roles/${roleId}/rights`, { rids: rids })
}
// power 修改角色提交的接口调用
export const setRolesOkApi = (id, rid) => {
  return axios.put(`users/${id}/role`, { rid: rid })
}
// goods 获取商品分类数据列表接口调用
export const getGoodsListApi = (data) => {
  return axios.get('categories', { params: data })
}
// goods 添加分类的接口调用
export const addCateApi = (data) => {
  return axios.post('categories', data)
}
// goods 获取参数列表（动态/静态参数）
export const getParamsApi = (id, sel) => {
  return axios.get(`categories/${id}/attributes`, { params: { sel: sel } })
}
// goods 添加动态/静态参数的接口调用
export const addApi = (id, data) => {
  return axios.post(`categories/${id}/attributes`, data)
}
// goods 编辑提交参数
export const editParamsApi = (cateId, attrId, data) => {
  return axios.put(`categories/${cateId}/attributes/${attrId}`, data)
}
// goods 删除参数
export const deleteParamsApi = (cateId, attrId) => {
  return axios.delete(`categories/${cateId}/attributes/${attrId}`)
}
// 商品列表数据的获取
export const getAllGoodsListApi = (data) => {
  return axios.get('goods', { params: data })
}
// 添加商品的接口调用
export const addGoodsApi = (data) => {
  return axios.post('goods', data)
}
// 获取所有订单列表
export const getOrderListApi = (data) => {
  return axios.get('orders', { params: data })
}
// 获取物流信息
export const orderMsgApi = () => {
  return axios.get(`/kuaidi/1106975712662`)
}
// 获取时间统计数据
export const timeDataApi = () => {
  return axios.get('reports/type/1')
}
